package com.automannn.atm_back.modules.codeGenerator.service.impl;

import com.automannn.atm_back.modules.codeGenerator.core.pojo.ColumnInfo;
import com.automannn.atm_back.modules.codeGenerator.core.pojo.TableInfo;
import com.automannn.atm_back.modules.codeGenerator.entity.ColumnEntity;
import com.automannn.atm_back.modules.codeGenerator.entity.TableEntity;
import com.automannn.atm_back.modules.codeGenerator.environment.EnvironmentPerception;
import com.automannn.atm_back.modules.codeGenerator.mapper.SchemaEntityMapper;
import com.automannn.atm_back.modules.codeGenerator.service.SchemaEntityService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author chenkh
 * @time 2020/6/29 20:44
 */
@Service
public class SchemaEntityServiceImpl implements SchemaEntityService {

    @Resource
    private SchemaEntityMapper schemaEntityMapper;

    @Override
    public IPage<TableEntity> queryAllTables(IPage page, String namespace) {
        List<TableEntity> list = new ArrayList<>();
        switch (EnvironmentPerception.getDatasourceType()){
            case MYSQL:
               list= schemaEntityMapper.getMysqlTables(page,namespace);
                break;
            case POSTGRE_SQL:
                list= schemaEntityMapper.getPGTables(page);
                break;
            case ORACLE:
                list= schemaEntityMapper.getOracleTables(page);
                break;
            case SQL_SERVER:
                list=schemaEntityMapper.getSqlServerTables(page);
                break;
            default:
                break;
        }
        page.setRecords(list);
        return page;
    }

    @Override
    public List<ColumnEntity> queryAllColumn(String table) {
        List<ColumnEntity> list = new ArrayList<>();
        switch (EnvironmentPerception.getDatasourceType()){
            case MYSQL:
                list= schemaEntityMapper.getMysqlColumns(table,EnvironmentPerception.getNamespace());
                break;
            case POSTGRE_SQL:
                list= schemaEntityMapper.getPGColumns(table);
                break;
            case ORACLE:
                list= schemaEntityMapper.getOracleColumns(table);
                break;
            case SQL_SERVER:
                list=schemaEntityMapper.getSqlServerColumns(table);
                break;
            default:
                break;
        }
        return list;
    }

    @Override
    public List<TableInfo> queryAllTableInfo(String namespace) {
        return null;
    }

    @Override
    public List<ColumnInfo> queryAllColumnInfo(String table) {
        return null;
    }
}
